package com.dcdrake.testApp;

import java.util.ArrayList;
import android.widget.AdapterView.OnItemClickListener;
import classes.Event;
import classes.EventArrayAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;


public class CampusEventsActivity extends Activity implements OnItemClickListener{
	Event event;
	ArrayList<Event> list;
	//private final String TAG = "debugTAG";
	public static final String PREFERENCE_FILENAME = "gamePrefs";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		ListView listView = (ListView) findViewById(R.id.list);
		list = ((myApp) this.getApplication()).getList();

		if(list == null){
			list = new ArrayList<Event>();
		}
		final EventArrayAdapter adapter = new EventArrayAdapter(this, list);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);

	}


	public void onClick(View view){
		switch (view.getId()){

		case R.id.add_event:
			((myApp) this.getApplication()).setList(list);
			Intent addIntent = new Intent(view.getContext(), AddEventActivity.class);
			startActivity(addIntent);
			//finish();
			break;

		case R.id.sort_date:
			//Add stuff here
			break;

		case R.id.sort_loc:
			//Add stuff here
			break;
		}
	}

	public void onDestroy(){
		super.onDestroy();
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View view, int pos, long arg3) {
		((myApp) this.getApplication()).setList(list);
		Intent descIntent = new Intent(view.getContext(), ViewDescriptionActivity.class);
		descIntent.putExtra("listIndex", pos);
		startActivity(descIntent);
		//finish();
	}

}